<script setup >
import {ref,computed} from 'vue'
import { onLoad } from '@dcloudio/uni-app'
import {postDeliverApi} from '@/apis/task'
// 任务id
const taskId = ref('')
// 上传图片的列表
const deliverPictureList = ref([
  {url:'https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/uni-app.png'}
])
// 上传图片的列表
const certificatePictureList = ref([
{url:'https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/uni-app.png'}
])
// 判断提交按钮是否显示
const enableSubmit = computed(() => {
  return deliverPictureList.value.length>0 && certificatePictureList.value.length>0
})
// 提交的方法
const onFormSubmit = async() => {
  const formData = {
    id:taskId.value,
    deliverPictureList:deliverPictureList.value,
    certificatePictureList:certificatePictureList.value
  }
  const res = await postDeliverApi(formData)
  if (res.code === 200) {
    console.log(res);
    uni.reLaunch({ url: '/pages/task/index' })
  }
}

onLoad((e) => {
  taskId.value = e.id
})

</script>
<template>
  <view class="page-container">
    <view class="receipt-info">
      <uni-file-picker limit="3" title="请拍照上传回单凭证"></uni-file-picker>
      <uni-file-picker limit="3" title="请拍照上传货品照片"></uni-file-picker>
    </view>
    <button :disabled="!enableSubmit" @click="onFormSubmit" class="button">提交</button>
  </view>
</template>
<style lang="scss" scoped>
  .page-container {
    padding: 30rpx;
  }

  .receipt-info {
    min-height: 600rpx;
    background-color: #fff;
    padding: 20rpx 30rpx;
    border-radius: 16rpx;

    ::v-deep .uni-file-picker {
      margin-bottom: 30rpx;
    }
  }

  .button {
    height: 100rpx;
    text-align: center;
    line-height: 100rpx;
    /* #ifdef APP */
    padding-top: 4rpx;
    /* #endif */
    border-radius: 100rpx;
    margin-top: 60rpx;
    color: #fff;
    font-size: $uni-font-size-big;
    background-color: $uni-primary;

    &[disabled] {
      color: #fff;
      background-color: #fadcd9;
    }
  }
</style>
